package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Description NursingPlan
 * @Author xun
 * @Date 2025-08-31
 */
@Slf4j
@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/plan/search")
    @ApiOperation("分页查询护理计划列表")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String planName,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> nursingPlanPageInfo = nursingPlanService.getByPage(planName, status, pageNum, pageSize);
        return success(nursingPlanPageInfo);
    }

    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> findAll() {
        return success(nursingPlanService.findAll());
    }


    @GetMapping("/plan/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlan> findById(@PathVariable Integer id) {

        log.info("根据id查询护理,id:{}", id);
        NursingPlan nv = nursingPlanService.findById(id);
        return success(nv);
    }

    @PostMapping("/plan")
    @ApiOperation("新增护理计划")
    public ResponseResult add(@RequestBody NursingPlanVo plan){
        log.info("新增护理计划");
        nursingPlanService.add(plan);
        return success();
    }

    /*// 修改护理计划
    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateById(@RequestBody NursingProjectPlanVo nursingProjectPlanVo) {
        nursingPlanService.updateById(nursingProjectPlanVo);
        return success();
    }*/

    // 删除护理计划
    @DeleteMapping("/plan/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult<Void> deleteNursingPlan(@PathVariable Long id) {
        log.info("删除护理计划, id:{}", id);
        nursingPlanService.deleteNursingPlan(id);
        return success();
    }

    // 启用禁用护理计划
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    public ResponseResult<Void> updateNursingPlanStatus(
            @PathVariable Long id,
            @PathVariable Integer status) {
        log.info("更新护理计划状态, id:{}, status:{}", id, status);
        nursingPlanService.updateNursingPlanStatus(id, status);
        return success();
    }




    @PutMapping("plan/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateById(@RequestBody NursingProjectPlanVo nursingProjectPlanVo){
        nursingPlanService.updateById(nursingProjectPlanVo);
        return success();
    }
}
